﻿using System;
using System.Threading.Tasks;
using wx_api.CSM.Common;
using wx_api.CSM.Dto;

namespace wx_api.CSM.plugins
{
    internal class StatusPlug : WxApiPluginBase
    {
        protected override string ListenUri { get; } = "/wx-api/status";
        protected override async Task OnRequest(WxApiSession session)
        {
            if (session.IsGet(ListenUri))
            {
                var output = new WxApiOutput();
                output.Success = true;
                if (output.Success)
                {
                    var info= new DriveInfo(Environment.CurrentDirectory);
                    output.Method = "status";
                    output.Params["disk"] = new
                    {
                        total = info.TotalSize,
                        free = info.AvailableFreeSpace,
                    };
                    output.Params["version"] = 10;
                    goto SEND_APP_REP;
                }
            SEND_APP_REP:
                await session.Send(200, output)
                    .AnswerAsync();
            }
            await session.InvokeNext();
        }
    }
}
